package com.xuecheng.content.api.controller;


import com.github.pagehelper.PageInfo;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.model.po.CourseBaseInfo;
import com.xuecheng.content.service.CourseBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author Mr.M
 * @version 1.0
 * @description 课程基本信息接口
 * @date 2024/12/15 11:06
 */
@Slf4j
@Api(value = "课程基本信息接口", tags = "课程基本信息接口")
@RestController
public class CourseBaseInfoController {
    @Autowired
    private CourseBaseInfoService courseBaseInfoService;

    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required = false) QueryCourseParamsDto queryCourseParamsDto) {
        //当前登录用户
        //  SecurityUtil.XcUser user = SecurityUtil.getUser();
        //用户所属机构id
        Long companyId = 1232141425L;
        PageResult<CourseBase> courseBasePageResult = courseBaseInfoService.queryCourseBaseList(companyId, pageParams, queryCourseParamsDto);
        log.info("查询课程列表，参数：{}，结果：{}", queryCourseParamsDto, courseBasePageResult);
        return courseBasePageResult;
    }


    @ApiOperation("新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseInfoDto createBaseInfoDto(@RequestBody AddCourseDto addCourseDto) {
        Long companyId = 1232141425L;
        log.info("新增课程基础信息，参数：{}，结果：{}", addCourseDto, new CourseBaseInfoDto());
        return courseBaseInfoService.createCourseBase(companyId, addCourseDto);
    }


    @ApiOperation("获取单个课程基础信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseInfo(@PathVariable Long courseId) {
        log.info("修改课程基础信息，参数：{}，结果：{}", courseId, courseBaseInfoService.getCourseBaseInfo(courseId));
        return courseBaseInfoService.getCourseBaseInfo(courseId);
    }


    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated EditCourseDto editCourseDto) {
        Long companyId = 1232141425L;
        log.info("修改课程基础信息，参数：{}，结果：{}", editCourseDto, courseBaseInfoService.updateCourseBase(companyId, editCourseDto));
        return courseBaseInfoService.updateCourseBase(companyId, editCourseDto);
    }




}
